#!/bin/bash

set -e

CURRENT_DIR=$(pwd)
NGINXD_ROOT_DIR=$CURRENT_DIR/../bin/nginxd
NAME=nginxd

start_nginxd()
{
    cd $NGINXD_ROOT_DIR/sbin
    sudo ./nginx -p $NGINXD_ROOT_DIR
}

shut_nginxd()
{
    cd $NGINXD_ROOT_DIR/sbin
    sudo ./nginx -s stop -p $NGINXD_ROOT_DIR
}


case "$1" in
  start)
    start_nginxd
  ;;
  stop)
    shut_nginxd
  ;;
  restart)
    shut_nginxd
    start_nginxd
  ;;
  *)
    echo "Usage: $NAME {start|stop|restart}" >&2
    exit 2
  ;;
esac
